package com.jdzy.student.controller;

import com.jdzy.model.common.vos.ResultA;
import com.jdzy.student.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@CrossOrigin(allowCredentials ="true",origins = "*",allowedHeaders = "*")
@RequestMapping("/api/file")
@RestController
public class FileUploadController {

    @Autowired
    private FileService service;

    @PostMapping("upload")
    public ResultA<String> upload(@RequestParam MultipartFile file,@RequestParam String stuId) {
        try {
            String url = service.upload(file, stuId);
            return ResultA.ok(url);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultA.fail();
        }
    }
}